package ru.paswd.marketprice.rest.app.controllers.v1;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RestController;
import ru.paswd.marketprice.rest.api.ProductApi;
import ru.paswd.marketprice.rest.api.dto.*;
import ru.paswd.marketprice.rest.app.services.PriceHistoryService;
import ru.paswd.marketprice.rest.app.services.PriceService;
import ru.paswd.marketprice.rest.app.services.ProductService;
import ru.paswd.marketprice.rest.app.services.ReceiptService;

import java.util.List;
import java.util.UUID;

@RestController
@RequiredArgsConstructor
public class ProductController implements ProductApi {

    private final ReceiptService receiptService;
    private final ProductService productService;
    private final PriceService priceService;
    private final PriceHistoryService priceHistoryService;

    @Override
    public List<ProductCategory> getProductCategories() {
        return productService.getProductCategories();
    }

    @Override
    public PageResponse<Product> getProducts(String name, String category, Pageable pageable) {
        return new PageResponse<>(productService.getProducts(name, category, pageable));
    }

    @Override
    public List<PriceWithShop> getPriceList(
            UUID productId, Integer radiusMeters, Double lat, Double lng, Boolean sortByPrice) {
        return priceService.getPriceList(productId, radiusMeters, lat, lng, sortByPrice);
    }

    @Override
    public void saveReceipt(ReceiptInfo receiptInfo) {
        receiptService.saveReceipt(receiptInfo);
    }

    @Override
    public List<Price> getPriceHistory(UUID shopId, UUID productId) {
        return priceHistoryService.getHistory(shopId, productId);
    }
}
